<?php

/*

Free Food (free_food.php)

*/

$page_title = "Free Food";
$rank_check = 1;
include "header.inc.php";

print "$openHTML<br>";

// Start Check

$checking = "freefood";
$limit1 = 7200;
$limit = $timestamp - $limit1;

$findCheck = fetch("SELECT * FROM checking2 WHERE userid = '$userid' AND check_what = '$checking' AND timestamp > '$limit'");

// End Check

if ($act == "feedme")
{
	if ($findCheck[id])
	{
		die("<p>You can only get free food ONCE per serving time. <a href=$base_url/free_food.php?game=$game>Back</a></p>$closeHTML");
	}

	$randHunger = rand(1,4);

	mysql_query("UPDATE members2 SET hunger_level = hunger_level + $randHunger WHERE username = '$username' AND game = '$game'");

	mysql_query("UPDATE user_pets2 SET hunger = hunger + $randHunger WHERE owner = '$userid' AND game = '$game'");

	mysql_query("UPDATE members2 SET hunger_level = 10 WHERE username = '$username' AND game = '$game' AND hunger_level > '10'");

	mysql_query("UPDATE user_pets2 SET hunger = 10 WHERE owner = '$userid' AND game = '$game' AND hunger > '10'");

	if ($randHunger == "1") { $pageTitle = "Slim Pickings"; }
	if ($randHunger == "2") { $pageTitle = "Satisfying Meal"; }
	if ($randHunger == "3") { $pageTitle = "3 Course Meal"; }
	if ($randHunger == "4")
	{
		$pageTitle = "Feasting!";

		mysql_query("UPDATE members2 SET hunger_level = 10 WHERE username = '$username' AND game = '$game'");

		mysql_query("UPDATE user_pets2 SET hunger = 10 WHERE owner = '$userid' AND game = '$game'");
	}

	mysql_query("DELETE FROM checking2 WHERE userid = '$userid' AND check_what = '$checking'");
	mysql_query("INSERT INTO checking2 (userid,check_what,timestamp,game) VALUES ('$userid','$checking','$timestamp','$game')");

	$findPage = fetch("SELECT * FROM game_pages WHERE page_title = '$pageTitle' AND game = '$game'");
	if (!$findPage[id])
	{
		if ($randHunger == "1") { print "<p>Sorry, but hardly anyone in the community has been donating, we only have left overs from yesterdays meal.</p>"; }
		if ($randHunger == "2") { print "<p>Here you go, the main course and an ice cold drink!</p>"; }
		if ($randHunger == "3") { print "<p>Quite a few people in the community have been donating! You get a full three course meal!!</p>"; }
		if ($randHunger == "4") { print "<p>WOW! A big food drive has just been completed, you FEAST on food and you and your pets are all full!</p>"; }
	}
	else
	{
		print "$findPage[page_info]";
	}
}

if ($act != "feedme")
{

	$findPage = fetch("SELECT * FROM game_pages WHERE page_title = '$page_title' AND game = '$game'");
	if (!$findPage[id])
	{
		print "<p>Welcome to the Soup Kitcen, we serve food to the needy every day. So put your pride aside and take some food :)</p>
		<p>Business hours:<Br>
		7 AM to 8 AM EST<br>
		11 AM to 1 PM EST and<Br>
		6 PM to 7 PM EST</p>
		";
	}
	else
	{
		print "$findPage[page_info]";
	}

	if ((($hour >= 07) AND ($hour <= 08)) OR (($hour >= 11) AND ($hour <= 13)) OR (($hour >= 18) AND ($hour <= 9)) AND (!$findCheck[id]))
	{
		print "<p align=center><a href=free_food.php?act=feedme&game=$game>Get your meal!</a></p>";
	}
	else
	{
		print "<p align=center><b>Sorry, we're closed now, come back during serving hours.</b></p>";
	}
}

print "$closeHTML";
?>